#!/bin/bash
set -euxo pipefail
rm -rf /tmp/rubyfmt_release /tmp/rubyfmt_source

git clone ./.git /tmp/rubyfmt_release
(
cd /tmp/rubyfmt_release
git checkout "$1"
git archive --format=zip HEAD > archive.zip
git submodule init
git submodule update
(
cd librubyfmt/ruby_checkout/
git reset --hard && git clean -fdx
)
mkdir /tmp/rubyfmt_source
unzip archive.zip -d /tmp/rubyfmt_source
cp -r librubyfmt/ruby_checkout/ /tmp/rubyfmt_source/librubyfmt/ruby_checkout/
)
tar -cvz -f "rubyfmt-$1-sources.tar.gz" -C "/tmp/rubyfmt_source" .
mkdir -p "out/release/source"
mv "rubyfmt-$1-sources.tar.gz" "out/release/source"
